<?php

include_once 'DB.php';

class person {

    public $Name;
    public $Password;
    public $Email;
    public $Phone_Number;
    public $profile;

    public function getname() {
        echo'welcome ' . $this->name;
    }

    public function setname($username) {
        $this->Name = $username;
    }

    public function setpass($userpass) {
        $this->Password = $userpass;
    }

    public function Login($data_base) {
        
        $User_Info = array("*", "customer", "name", $this->Name, "Position", "Customer");
        $User = new person ();
        $Usera = $data_base->SelectPerson($User_Info);
        $User->name = $Usera[0];
        $User->password = $Usera[1];
        if ($User->name == $this->Name && $User->password == $this->Password) {

            $this->setpass($User->password);
            $this->profile = 'customer';

            echo'<center><h1>WELCOME  ' . $this->Name . ' :</h1></center></br>
			<center><P style="color:SandyBrown;font-size:22px;">
                        <form method="POST" action="'.$this->profile.'.php" style="color:SandyBrown;font-size:15px;">-> Continue  <input type="submit" 	value="GO !" /></br></br></form>
			<form method="POST" action="HomePage.php" style="color:SandyBrown;font-size:15px;">-> Logout<input type="submit" value="GO !" /></br></br></form>
			</P></center>';

            return;
        } else if ($User->name == $this->Name && $User->password != $this->Password) {
            echo '<P style="color:SandyBrown;font-size:22px;"></br>Dear ' . $User->name . ' , </br> </br>You Have Entered The Wrong Password .
			</br></br>Please Try Again  <a href ="Login.php"><input type="submit" value="Back" /></a> </p>';
        } else {

        //EMPLOYEE TABLE
            //$User_Info[1]="employee";
            //$User_Info[5]="Employee";
            $User_Info = array("*", "employee", "name", $this->Name, "Position", "Employee");
            $User = new person ();
            $Usera = $data_base->SelectPerson($User_Info);
            $User->name = $Usera[0];
            $User->password = $Usera[1];
            if ($User->name == $this->Name && $User->password == $this->Password) {

                $this->setpass($User->password);
                $this->profile = 'Employee';

                echo'<center><h1>WELCOME  ' . $this->Name . ' :</h1></center></br>
                    <center><P style="color:SandyBrown;font-size:22px;">
                  <form method="POST" action="'.$this->profile.'.php" style="color:SandyBrown;font-size:15px;">-> Continue <input type="submit" value="GO !" /></br></br></form>  
		<form method="POST" action="Logout.php" style="color:SandyBrown;font-size:15px;">-> Logout <input type="submit" 	value="GO !" /></br></br></form>
					</P></center>';
                return;
            } else if ($User->name == $this->Name && $User->password != $this->Password) {
                echo '<P style="color:SandyBrown;font-size:22px;"></br>Dear ' . $User->name . ' , </br> </br>You Have Entered The Wrong Password .
				</br></br>Please Try Again  <a href ="Login.php"><input type="submit" value="Back" /></a> </p>';
            } else {
            //ADMIN TABLE
                $User_Info[1] = "employee";
                $User_Info[5] = "Admin";
                $User = new person ();
                $Usera = $data_base->SelectPerson($User_Info);
                $User->name = $Usera[0];
                $User->password = $Usera[1];
//				echo 'USER_'.$User->name.'__PASSWORD'.$User->password;
                if ($User->name == $this->Name && $User->password == $this->Password) {
                    $this->setpass($User->password);
                    $this->profile = 'Admin';

                    echo'<center><h1>WELCOME  ' . $this->Name . ' :</h1></center></br>
			<center><P style="color:SandyBrown;font-size:22px;">
			<form method="POST" action="' . $this->profile . '.php" style="color:SandyBrown;font-size:15px;">-> Continue <input type="submit" 	value="GO !" /></br></br></form>
			<form method="POST" action="Logout.php" style="color:SandyBrown;font-size:15px;">-> Logout <input type="submit" 	value="GO !" /></br></br></form>
				</P></center>';
                    return;
                } else if ($User->name == $this->Name && $User->password != $this->Password) {
                    echo '<P style="color:SandyBrown;font-size:22px;"></br>Dear ' . $User->name . ' , </br> </br>You Have Entered The Wrong Password .
		</br></br>Please Try Again  <a href ="Login.php"><input type="submit" value="Back" /></a> </p>';
                } else {
                    echo '<p style="color:SandyBrown;font-size:22px;"></br>You Have Entered An <b>Invalid Username And Password </b>.
</br></br>Please Try Again  <a href ="Login.php"><a href ="Login.php"><input type="submit" value="Login" /></a> .
							
</br></br>I Dont Have An Account  <a href ="Registration.php"><input type="submit" value="Create Account" /></a> .</p>';
                }
            }
        }
    }

    public function Logout()
	{
		session_destroy();
		Header("Location: HomePage.php");
	}
}
?>




